package com.jlcloud.core.log.aspect;

import com.jlcloud.core.log.utils.LogTraceUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * <p>利用AOP为日志增加TraceId</p>
 *
 * @author BY anyaowei
 * Package org.jobslink.core.log.aspect
 * Create Time 2024/10/9 14:48
 * Copyright 2021 www.jilianjituan.com Inc. All rights reserved.
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目的
 */
@Aspect
@Component
public class ScheduledLogTraceAspect {

	/**
	 * 拦截被@ScheduledLog注解的方法
	 */
	@Pointcut("@annotation(com.jlcloud.core.log.annotation.ScheduledLog)")
	public void scheduledLogPointcut() {

	}
	@Around("scheduledLogPointcut()")
	public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
		boolean flag = Boolean.FALSE;
		flag = LogTraceUtil.insert();
		try {
			return joinPoint.proceed();
		} finally {
			if (flag) {
				LogTraceUtil.remove();
			}
		}
	}
}
